home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / x / volume10 / tgif / patch6.02 < prev    next >
Encoding:
Internet Message Format  |  1990-12-17  |  45.0 KB

  1. Path: uunet!tut.cis.ohio-state.edu!att!news.cs.indiana.edu!julius.cs.uiuc.edu!usc!elroy.jpl.nasa.gov!lll-winken!sun-barr!newstop!exodus!CS.UCLA.EDU
  2. From: william@CS.UCLA.EDU (William Cheng)
  3. Newsgroups: comp.sources.x
  4. Subject: v10i065: tgif, Patch6, Part02/03
  5. Message-ID: <4699@exodus.Eng.Sun.COM>
  6. Date: 18 Dec 90 02:07:15 GMT
  7. References: <csx-10i064:tgif@uunet.UU.NET>
  8. Sender: news@exodus.Eng.Sun.COM
  9. Lines: 1553
  10. Approved: argv@sun.com
  11.  
  12. Submitted-by: william@CS.UCLA.EDU (William Cheng)
  13. Posting-number: Volume 10, Issue 65
  14. Archive-name: tgif/patch6.02
  15. Patch-To: Volume 7, Issue 56-76 (original: tgif-1.2)
  16. Patch-To: Volume 8, Issue 46-48 (Patch1: tgif-1.2 => tgif-1.9)
  17. Patch-To: Volume 8, Issue 58-60 (Patch2: tgif-1.9 => tgif-1.12)
  18. Patch-To: Volume 8, Issue 87-89 (Patch3: tgif-1.12 => tgif-1.13)
  19. Patch-To: Volume 8, Issue 94 (Patch4: tgif-1.13 => tgif-1.14)
  20. Patch-To: Volume 8, Issue 95 (Patch5: tgif-1.14 => tgif-1.15)
  21.  
  22. ---------------------------------> cut here <---------------------------------
  23. *** names.c.orig    Sat Oct 27 17:49:07 1990
  24. --- names.c    Sat Oct 27 17:49:08 1990
  25. ***************
  26. *** 6,10 ****
  27.   #ifndef lint
  28.   static char RCSid[] =
  29. !       "@(#)$Header: /n/kona/u/tangram/u/william/X11/TGIF/RCS/names.c,v 1.6 90/07/27 14:39:29 william Exp $";
  30.   #endif
  31.   
  32. --- 6,10 ----
  33.   #ifndef lint
  34.   static char RCSid[] =
  35. !       "@(#)$Header: /n/kona/u/tangram/u/william/X11/TGIF/RCS/names.c,v 1.10 90/10/26 15:40:34 william Exp $";
  36.   #endif
  37.   
  38. ***************
  39. *** 20,23 ****
  40. --- 20,24 ----
  41.   #include "button.e"
  42.   #include "cursor.e"
  43. + #include "file.e"
  44.   #include "font.e"
  45.   #include "mainloop.e"
  46. ***************
  47. *** 33,37 ****
  48. --- 34,50 ----
  49.   #define ROW_HEIGHT (defaultFontHeight+1)
  50.   
  51. + typedef struct _DspList {
  52. +    char            itemstr[MAXPATHLENGTH+1];
  53. +    char            pathstr[MAXPATHLENGTH+1];
  54. +    int            directory;
  55. +    struct _DspList    * next;
  56. + } DspList;
  57. + extern char    * getenv ();
  58.   char    curDomainName[MAXPATHLENGTH];
  59. + char    curDomainPath[MAXPATHLENGTH];
  60. + char    curDir[MAXPATHLENGTH];
  61. + char    curSymDir[MAXPATHLENGTH];
  62.   
  63.   static Window        nameBaseWin;
  64. ***************
  65. *** 55,61 ****
  66.   static GC    revNameGC;
  67.   
  68.   void InitNames ()
  69.   {
  70. !    char        * c_ptr;
  71.      XGCValues    values;
  72.   
  73. --- 68,342 ----
  74.   static GC    revNameGC;
  75.   
  76. + static DspList    * symbolList = NULL;
  77. + static int    numSymbols;
  78. + static DspList    * dirList = NULL;
  79. + static int    numDirEntries;
  80. + static DspList    * topOfSymLinkList = NULL;
  81. + static DspList    * topOfDirLinkList = NULL;
  82. + static
  83. + char * ReadPath (path_str, dir_str)
  84. +    char * path_str, * dir_str;
  85. + {
  86. +    register char        * s1, * s2;
  87. +    s1 = path_str;
  88. +    if (*s1 == '~')
  89. +    {
  90. +       strcpy (dir_str, homeDir);
  91. +       s2 = &dir_str[strlen(dir_str)];
  92. +       s1++;
  93. +    }
  94. +    else
  95. +       s2 = dir_str;
  96. +    for ( ; *s1 != '\0' && *s1 != ':'; s1++)
  97. +       if (*s1 == '\\')
  98. +          strcpy (s1, s1+1);
  99. +       else
  100. +          *s2++ = *s1;
  101. +    *s2 = '\0';
  102. +    if (*s1 == ':') s1++;
  103. +    return (s1);
  104. + }
  105. + void ParseSymPath (path_str)
  106. +    char * path_str;
  107. + {
  108. +    register char        * s, c;
  109. +    register int         i;
  110. +    char                 dir_str[MAXPATHLENGTH];
  111. +    for (i = 0, s = path_str; *s != '\0'; )
  112. +    {
  113. +       s = ReadPath (s, dir_str);
  114. +       if (dir_str != '\0') i++;
  115. +    }
  116. +    symPath = (char * *) calloc (i, sizeof (char *));
  117. +    symPathNumEntries = i;
  118. +    for (i = 0, s = path_str; *s != '\0'; )
  119. +    {
  120. +       s = ReadPath (s, dir_str);
  121. +       if (dir_str != '\0')
  122. +       {
  123. +          symPath[i] = (char *) calloc (MAXPATHLENGTH, sizeof (char));
  124. +          strcpy (symPath[i], dir_str);
  125. +          i++;
  126. +       }
  127. +    }
  128. +    strcpy (curDomainPath, path_str);
  129. + }
  130. + static
  131. + DspList * SymbolListing ()
  132. + {
  133. +    int            i, len, path_index, count = 0, reject;
  134. +    char            path[MAXPATHLENGTH], s[MAXPATHLENGTH];
  135. +    DspList        * dsp_ptr = NULL, * head_ptr, * tail_ptr, * p, * p1;
  136. +    DIR            * dirp;
  137. +    struct direct    * d;
  138. +    struct stat        stat_buf;
  139. +    head_ptr = tail_ptr = NULL;
  140. +    for (path_index = 0; path_index < symPathNumEntries; path_index++)
  141. +    {
  142. +       strcpy (path, symPath[path_index]);
  143. +       if ((dirp = opendir (path)) == NULL)
  144. +          continue;
  145. +       while ((d = readdir (dirp)) != NULL)
  146. +       {
  147. +          len = strlen (d->d_name);
  148. +          if (len > 4 && (strcmp (".sym", &d->d_name[len-4]) == 0))
  149. +             d->d_name[len-4] = '\0';
  150. +          else
  151. +             continue;
  152. +          if (head_ptr == NULL)
  153. +          {
  154. +             head_ptr = tail_ptr = (DspList *) calloc (1, sizeof(DspList));
  155. +             strcpy (head_ptr->itemstr, d->d_name);
  156. +             strcpy (head_ptr->pathstr, path);
  157. +          }
  158. +          else
  159. +          {
  160. +             p1 = NULL;
  161. +             reject = FALSE;
  162. +             for (p = head_ptr; p != NULL; p = p->next)
  163. +             {
  164. +                if (strcmp (d->d_name, p->itemstr) == 0)
  165. +                {
  166. +                   reject = TRUE;
  167. +                   break;
  168. +                }
  169. +                else if (LargerStr (d->d_name, p->itemstr))
  170. +                   p1 = p;
  171. +                else
  172. +                {
  173. +                   dsp_ptr = (DspList *) calloc (1, sizeof(DspList));
  174. +                   strcpy (dsp_ptr->itemstr, d->d_name);
  175. +                   strcpy (dsp_ptr->pathstr, path);
  176. +                   break;
  177. +                }
  178. +             }
  179. +             if (reject) continue;
  180. +    
  181. +             dsp_ptr = (DspList *) calloc (1, sizeof(DspList));
  182. +             dsp_ptr->next = p;
  183. +             strcpy (dsp_ptr->itemstr, d->d_name);
  184. +             strcpy (dsp_ptr->pathstr, path);
  185. +             if (p == NULL)
  186. +             {  /* dsp_ptr has the largest element */
  187. +                tail_ptr->next = dsp_ptr;
  188. +                tail_ptr = dsp_ptr;
  189. +             }
  190. +             else if (p1 == NULL)
  191. +                head_ptr = dsp_ptr;
  192. +             else
  193. +                p1->next = dsp_ptr;
  194. +          }
  195. +          count++;
  196. +       }
  197. +       closedir (dirp);
  198. +    }
  199. +    numSymbols = count;
  200. +    return (head_ptr);
  201. + }
  202. + static
  203. + void BuildSymbolList ()
  204. + {
  205. +    register int        i;
  206. +    register DspList    * dsp_ptr;
  207. +    if (symbolList != NULL) cfree (symbolList);
  208. +    symbolList = (DspList *) calloc (numSymbols, sizeof (DspList));
  209. +    dsp_ptr = topOfSymLinkList;
  210. +    for (i = 0; i < numSymbols; i++, dsp_ptr = dsp_ptr->next)
  211. +    {
  212. +       strcpy (symbolList[i].itemstr, dsp_ptr->itemstr);
  213. +       strcpy (symbolList[i].pathstr, dsp_ptr->pathstr);
  214. +       symbolList[i].next = &symbolList[i+1];
  215. +       cfree (dsp_ptr);
  216. +    }
  217. +    symbolList[numSymbols].next = NULL;
  218. +    topOfSymLinkList = NULL;
  219. + }
  220. + static
  221. + DspList * DirListing (Path)
  222. +    char    * Path;
  223. + {
  224. +    DspList        * dsp_ptr = NULL, * head_ptr, * tail_ptr, * p, * p1;
  225. +    DIR            * dirp;
  226. +    struct direct    * d;
  227. +    int            len, count = 0;
  228. +    char            path[MAXPATHLENGTH], s[MAXPATHLENGTH];
  229. +    struct stat        stat_buf;
  230. +    if (*Path == '\0')
  231. +    {
  232. +       strcpy (path, "/");
  233. +       if ((dirp = opendir (path)) == NULL) return (NULL);
  234. +    }
  235. +    else
  236. +    {
  237. +       strcpy (path, Path);
  238. +       if ((dirp = opendir (path)) == NULL) return (NULL);
  239. +       strcat (path, "/");
  240. +    }
  241. +    head_ptr = tail_ptr = NULL;
  242. +    while ((d = readdir (dirp)) != NULL)
  243. +    {
  244. +       len = strlen (d->d_name);
  245. +       if (len > 4 && (strcmp (".obj", &d->d_name[len-4]) == 0))
  246. +       {
  247. +          d->d_name[len-4] = '\0';
  248. +          dsp_ptr = (DspList *) calloc (1, sizeof(DspList));
  249. +          dsp_ptr->directory = FALSE;
  250. +          strcpy (dsp_ptr->itemstr, d->d_name);
  251. +       }
  252. +       else if (strcmp (d->d_name, ".") == 0)
  253. +          continue;
  254. +       else
  255. +       {
  256. +          strcpy (s, path);
  257. +          strcat (s, d->d_name);
  258. +          stat (s, &stat_buf);
  259. +          if (stat_buf.st_mode & S_IFDIR)
  260. +          {
  261. +             dsp_ptr = (DspList *) calloc (1, sizeof(DspList));
  262. +             dsp_ptr->directory = TRUE;
  263. +             strcat (d->d_name, "/");
  264. +             strcpy (dsp_ptr->itemstr, d->d_name);
  265. +          }
  266. +          else
  267. +             continue;
  268. +       }
  269. +       if (head_ptr == NULL)
  270. +          head_ptr = tail_ptr = dsp_ptr;
  271. +       else
  272. +       {
  273. +          p1 = NULL;
  274. +          for (p = head_ptr; p != NULL; p = p->next)
  275. +             if (LargerStr (d->d_name, p->itemstr))
  276. +                p1 = p;
  277. +             else
  278. +                break;
  279. +          dsp_ptr->next = p;
  280. +          if (p == NULL)
  281. +          {  /* dsp_ptr has the largest element */
  282. +             tail_ptr->next = dsp_ptr;
  283. +             tail_ptr = dsp_ptr;
  284. +          }
  285. +          else if (p1 == NULL)
  286. +             head_ptr = dsp_ptr;
  287. +          else
  288. +             p1->next = dsp_ptr;
  289. +       }
  290. +       count++;
  291. +    }
  292. +    closedir (dirp);
  293. +    numDirEntries = count;
  294. +    return (head_ptr);
  295. + }
  296. + static
  297. + void BuildDirList ()
  298. + {
  299. +    register int        i;
  300. +    register DspList    * dsp_ptr;
  301. +    if (topOfDirLinkList != NULL)
  302. +    {
  303. +       if (dirList != NULL) cfree (dirList);
  304. +       dirList = (DspList *) calloc (numDirEntries, sizeof (DspList));
  305. +       dsp_ptr = topOfDirLinkList;
  306. +       for (i = 0; i < numDirEntries; i++, dsp_ptr = dsp_ptr->next)
  307. +       {
  308. +          strcpy (dirList[i].itemstr, dsp_ptr->itemstr);
  309. +          strcpy (dirList[i].pathstr, dsp_ptr->pathstr);
  310. +          dirList[i].directory = dsp_ptr->directory;
  311. +          dirList[i].next = &dirList[i+1];
  312. +          cfree (dsp_ptr);
  313. +       }
  314. +       dirList[numDirEntries].next = NULL;
  315. +       topOfDirLinkList = NULL;
  316. +    }
  317. + }
  318.   void InitNames ()
  319.   {
  320. !    int        default_found = FALSE;
  321. !    char        * c_ptr, domain_str[20], sym_path[80];
  322.      XGCValues    values;
  323.   
  324. ***************
  325. *** 79,82 ****
  326. --- 360,366 ----
  327.   
  328.      *curDomainName = '\0';
  329. +    *curDomainPath = '\0';
  330. +    *curSymDir = '\0';
  331. +    strcpy (curDir, bootDir);
  332.   
  333.      if ((c_ptr = XGetDefault (mainDisplay, TOOL_NAME, "DoubleClickInterval")) !=
  334. ***************
  335. *** 85,90 ****
  336. --- 369,407 ----
  337.      else
  338.         doubleClickInterval = 300;
  339. +    if ((c_ptr = XGetDefault (mainDisplay, TOOL_NAME, "DefaultDomain")) != NULL)
  340. +    {
  341. +       sprintf (domain_str, "Domain%s", c_ptr);
  342. +       if ((c_ptr = XGetDefault (mainDisplay, TOOL_NAME, domain_str)) != NULL)
  343. +       {
  344. +          if (*c_ptr != '\0')
  345. +          {
  346. +             strcpy (curDomainName, c_ptr);
  347. +             sprintf (sym_path, "TGIF_%s", c_ptr);
  348. +             default_found = TRUE;
  349. +          }
  350. +       }
  351. +    }
  352. +    if (!default_found || (c_ptr = getenv (sym_path)) == NULL)
  353. +       ParseSymPath (".");
  354. +    else
  355. +       if (strlen (c_ptr) >= MAXPATHLENGTH-1)
  356. +          ParseSymPath (".");
  357. +       else 
  358. +          ParseSymPath (c_ptr);
  359. +    if ((topOfSymLinkList = SymbolListing ()) != NULL) BuildSymbolList ();
  360.   }
  361.   
  362. + void UpdateDirInfo ()
  363. + {
  364. +    if ((topOfDirLinkList = DirListing (curDir)) != NULL) BuildDirList ();
  365. + }
  366. + void UpdateSymInfo ()
  367. + {
  368. +    if ((topOfSymLinkList = SymbolListing ()) != NULL) BuildSymbolList ();
  369. + }
  370.   void CleanUpNames ()
  371.   {
  372. ***************
  373. *** 91,94 ****
  374. --- 408,414 ----
  375.      XFreeGC (mainDisplay, nameGC);
  376.      XFreeGC (mainDisplay, revNameGC);
  377. +    if (symbolList != NULL) cfree (symbolList);
  378. +    if (dirList != NULL) cfree (dirList);
  379.   }
  380.   
  381. ***************
  382. *** 145,149 ****
  383.      register int    i;
  384.      int        top, len, end, pixel;
  385. -    DspItem    * diptr;
  386.      XGCValues    values;
  387.   
  388. --- 465,468 ----
  389. ***************
  390. *** 181,188 ****
  391.   
  392.   static
  393. ! void RedrawNameBaseWindow (Str, str_start, button_start, W, H)
  394. !    char    * Str;
  395. !    int    str_start, button_start;
  396.   {
  397.      int    top = defaultFontAsc+2;
  398.   
  399. --- 500,536 ----
  400.   
  401.   static
  402. ! void RedrawNamePath (Path, X, Y)
  403. !    char    * Path;
  404. !    int    X, Y;
  405.   {
  406. +    int    len = strlen (Path), cursor_x, cursor_y;
  407. +    char    * c_ptr;
  408. +    cursor_y = Y-defaultFontAsc;
  409. +    XClearArea (mainDisplay, nameBaseWin, X, Y-defaultFontAsc,
  410. +          ITEM_LEN*defaultFontWidth+4, defaultFontHeight+4, False);
  411. +    XDrawRectangle (mainDisplay, nameBaseWin, nameGC, X, cursor_y-2,
  412. +          ITEM_LEN*defaultFontWidth+8, defaultFontHeight+4);
  413. +    if (len > ITEM_LEN)
  414. +    {
  415. +       c_ptr = &(Path[len-ITEM_LEN]);
  416. +       len = ITEM_LEN;
  417. +    }
  418. +    else
  419. +       c_ptr = Path;
  420. +    cursor_x = X+2+len*defaultFontWidth;
  421. +    XDrawString (mainDisplay, nameBaseWin, nameGC, X+2, Y, c_ptr, len);
  422. +    XDrawLine (mainDisplay, nameBaseWin, nameGC, cursor_x,
  423. +          cursor_y, cursor_x, cursor_y+defaultFontHeight);
  424. + }
  425. + static
  426. + void RedrawNameBaseWindow (Str, Path, str_start, path_start, button_start, W, H)
  427. +    char    * Str, * Path;
  428. +    int    str_start, path_start, button_start, W, H;
  429. + {
  430.      int    top = defaultFontAsc+2;
  431.   
  432. ***************
  433. *** 190,199 ****
  434.      XDrawString (mainDisplay, nameBaseWin, nameGC, str_start,
  435.            ROW_HEIGHT+top, Str, strlen(Str));
  436.   
  437. !    buttonBBox[0].lty = buttonBBox[1].lty = (ITEM_DSPED+4) * ROW_HEIGHT;
  438.      buttonBBox[0].ltx = button_start;
  439. !    DisplayButton (nameBaseWin, "OK", 8, &buttonBBox[0], BUTTON_NORMAL);
  440.      buttonBBox[1].ltx = buttonBBox[CONFIRM_YES].rbx + 1 + defaultFontWidth;
  441. !    DisplayButton (nameBaseWin, "CANCEL", 8, &buttonBBox[1],
  442.            BUTTON_NORMAL);
  443.   }
  444. --- 538,548 ----
  445.      XDrawString (mainDisplay, nameBaseWin, nameGC, str_start,
  446.            ROW_HEIGHT+top, Str, strlen(Str));
  447. +    RedrawNamePath (Path, path_start, 3*ROW_HEIGHT+top);
  448.   
  449. !    buttonBBox[0].lty = buttonBBox[1].lty = (ITEM_DSPED+6) * ROW_HEIGHT;
  450.      buttonBBox[0].ltx = button_start;
  451. !    DisplayButton (nameBaseWin, "OK", 8, &(buttonBBox[0]), BUTTON_NORMAL);
  452.      buttonBBox[1].ltx = buttonBBox[CONFIRM_YES].rbx + 1 + defaultFontWidth;
  453. !    DisplayButton (nameBaseWin, "CANCEL", 8, &(buttonBBox[1]),
  454.            BUTTON_NORMAL);
  455.   }
  456. ***************
  457. *** 213,221 ****
  458.         dsp_ptr[i] = c_ptr;
  459.         len = strlen (DLPtr->itemstr);
  460. !       for (j = len; j >= 0 && DLPtr->itemstr[j] != '/'; j--) ;
  461. !       if (j >= 0)
  462. !          strcpy (c_ptr, (&DLPtr->itemstr[j])+1);
  463.         else
  464.            strcpy (c_ptr, DLPtr->itemstr);
  465.         c_ptr += MAXPATHLENGTH;
  466.      }
  467. --- 562,576 ----
  468.         dsp_ptr[i] = c_ptr;
  469.         len = strlen (DLPtr->itemstr);
  470. !       if (!DLPtr->directory)
  471. !       {
  472. !          for (j = len; j >= 0 && DLPtr->itemstr[j] != '/'; j--) ;
  473. !          if (j >= 0)
  474. !             strcpy (c_ptr, (&(DLPtr->itemstr[j]))+1);
  475. !          else
  476. !             strcpy (c_ptr, DLPtr->itemstr);
  477. !       }
  478.         else
  479.            strcpy (c_ptr, DLPtr->itemstr);
  480.         c_ptr += MAXPATHLENGTH;
  481.      }
  482. ***************
  483. *** 343,362 ****
  484.   
  485.   static
  486. ! int Names (Str)
  487. !    char    * Str;
  488.   {
  489. !    int        x, y, pixel, button_widths, str_width, graph_width, w, h;
  490. !    int        str_start, button_start, graph_start, index;
  491. !    int        dsp_w, dsp_h;
  492. !    XEvent    input, ev;
  493. !    int        i, len, looping = TRUE, grabbed = FALSE;
  494. !    char        buf[80];
  495. !    XKeyEvent    * key_ev;
  496. !    XButtonEvent    * button_ev;
  497. !    KeySym    key_sym;
  498.      XComposeStatus    c_stat;
  499.      XSetWindowAttributes    win_attrs;
  500. !    int        win_x, win_y, win_w, win_h, win_d, win_brdr_w;
  501. !    Window    root_win;
  502.   
  503.      dsp_w = DisplayWidth (mainDisplay, mainScreen);
  504. --- 698,729 ----
  505.   
  506.   static
  507. ! int LargerStr (S1, S2)
  508. !    register char    * S1, * S2;
  509. !    /* returns TRUE if S1 > S2 */
  510.   {
  511. !    while (*S1 == *S2 && *S1 != '\0' && *S2 != '\0') { S1++; S2++; }
  512. !    return (*S1 > *S2);
  513. ! }
  514. ! static
  515. ! int DirNames (TopStr, SelStr)
  516. !    char    * TopStr, * SelStr;
  517. ! {
  518. !    int            pixel, button_widths, str_width, graph_width;
  519. !    int            str_start, button_start, graph_start, index;
  520. !    int            dsp_w, dsp_h, x, y, w, h, i, len, exposure = 0;
  521. !    XEvent        input, ev;
  522. !    int            looping = TRUE, changing, grabbed = FALSE, name_index;
  523. !    char            buf[80], name[MAXPATHLENGTH], full_name[MAXPATHLENGTH];
  524. !    char            dir_name[MAXPATHLENGTH], sel_str[MAXPATHLENGTH];
  525. !    XKeyEvent        * key_ev;
  526. !    XButtonEvent        * button_ev;
  527. !    KeySym        key_sym;
  528.      XComposeStatus    c_stat;
  529.      XSetWindowAttributes    win_attrs;
  530. !    int            win_x, win_y, win_w, win_h, win_d, win_brdr_w;
  531. !    Window        root_win;
  532. !    DspList        * dsp_ptr, * head_dsp_ptr;
  533.   
  534.      dsp_w = DisplayWidth (mainDisplay, mainScreen);
  535. ***************
  536. *** 365,369 ****
  537.      button_widths = ButtonWidth("OK", 8) + ButtonWidth("CANCEL", 8) +
  538.            defaultFontWidth;
  539. !    str_width = defaultFontWidth * strlen (Str);
  540.      graph_width = nameDspWinW + scrollBarW + 2 * brdrW;
  541.   
  542. --- 732,736 ----
  543.      button_widths = ButtonWidth("OK", 8) + ButtonWidth("CANCEL", 8) +
  544.            defaultFontWidth;
  545. !    str_width = defaultFontWidth * strlen (TopStr);
  546.      graph_width = nameDspWinW + scrollBarW + 2 * brdrW;
  547.   
  548. ***************
  549. *** 381,385 ****
  550.      }
  551.      button_start = (w - button_widths) / 2;
  552. !    h = (6 + ITEM_DSPED) * ROW_HEIGHT;
  553.   
  554.      win_x = (w > dsp_w) ? 0 : (dsp_w - w)/2;
  555. --- 748,752 ----
  556.      }
  557.      button_start = (w - button_widths) / 2;
  558. !    h = (8 + ITEM_DSPED) * ROW_HEIGHT;
  559.   
  560.      win_x = (w > dsp_w) ? 0 : (dsp_w - w)/2;
  561. ***************
  562. *** 393,397 ****
  563.   
  564.      if ((nameDspWin = XCreateSimpleWindow (mainDisplay, nameBaseWin, graph_start,
  565. !          3*ROW_HEIGHT, nameDspW, nameDspH, brdrW, myBorderPixel,
  566.            myBgPixel)) == 0)
  567.      { printf ("Could not create desired popup window!\n"); exit (-1); }
  568. --- 760,764 ----
  569.   
  570.      if ((nameDspWin = XCreateSimpleWindow (mainDisplay, nameBaseWin, graph_start,
  571. !          5*ROW_HEIGHT, nameDspW, nameDspH, brdrW, myBorderPixel,
  572.            myBgPixel)) == 0)
  573.      { printf ("Could not create desired popup window!\n"); exit (-1); }
  574. ***************
  575. *** 398,402 ****
  576.   
  577.      if ((nameScrollWin = XCreateSimpleWindow (mainDisplay, nameBaseWin,
  578. !          graph_start+nameDspWinW, 3*ROW_HEIGHT, scrollBarW, nameDspH,
  579.            brdrW, myBorderPixel, myBgPixel)) == 0)
  580.      { printf ("Could not create desired popup scroll window!\n"); exit (-1); }
  581. --- 765,769 ----
  582.   
  583.      if ((nameScrollWin = XCreateSimpleWindow (mainDisplay, nameBaseWin,
  584. !          graph_start+nameDspWinW, 5*ROW_HEIGHT, scrollBarW, nameDspH,
  585.            brdrW, myBorderPixel, myBgPixel)) == 0)
  586.      { printf ("Could not create desired popup scroll window!\n"); exit (-1); }
  587. ***************
  588. *** 419,425 ****
  589. --- 786,1122 ----
  590.            KeyPressMask | ButtonPressMask | ExposureMask);
  591.   
  592. +    strcpy (dir_name, curDir);
  593.      justClicked = FALSE;
  594.      while (looping)
  595.      {
  596. +       nameEntries = numDirEntries;
  597. +       if (topOfDirLinkList == NULL)
  598. +          nameDspPtr = MakeNameDspItemArray (nameEntries, dirList);
  599. +       else
  600. +          nameDspPtr = MakeNameDspItemArray (nameEntries, topOfDirLinkList);
  601. +       nameFirst = 0;
  602. +       nameMarked = 0;
  603. +       strcpy (full_name, dir_name);
  604. +       strcat (full_name, "/");
  605. +       name[0] = '\0';
  606. +       name_index = 0;
  607. +       if (exposure >= 3)
  608. +       {
  609. +          XClearWindow (mainDisplay, nameBaseWin);
  610. +          XClearWindow (mainDisplay, nameDspWin);
  611. +          XClearWindow (mainDisplay, nameScrollWin);
  612. +          RedrawNameBaseWindow (TopStr, full_name, str_start, graph_start,
  613. +                button_start, w, h);
  614. +          RedrawNameScrollWin ();
  615. +          RedrawDspWindow ();
  616. +       }
  617. +       changing = TRUE;
  618. +       while (changing)
  619. +       {
  620. +          XNextEvent (mainDisplay, &input);
  621. +          if (input.type == Expose)
  622. +          {
  623. +             if (input.xany.window == nameBaseWin)
  624. +             {
  625. +                RedrawNameBaseWindow (TopStr, full_name, str_start, graph_start,
  626. +                      button_start, w, h);
  627. +                exposure++;
  628. +             }
  629. +             else if (input.xany.window == nameScrollWin)
  630. +             {
  631. +                RedrawNameScrollWin ();
  632. +                exposure++;
  633. +             }
  634. +             else if (input.xany.window == nameDspWin)
  635. +             {
  636. +                RedrawDspWindow ();
  637. +                exposure++;
  638. +             }
  639. + /*          if (!grabbed)
  640. +             {
  641. +                XGrabKeyboard (mainDisplay, nameBaseWin, False,
  642. +                      GrabModeAsync, GrabModeAsync, CurrentTime);
  643. +                grabbed = TRUE;
  644. +             } */
  645. +             continue;
  646. +          }
  647. +          else if (input.type == KeyPress)
  648. +          {
  649. +             key_ev = &(input.xkey);
  650. +             XLookupString (key_ev, buf, 80, &key_sym, &c_stat);
  651. +             if ((buf[0]=='\r' && (key_sym & 0xff)=='\r') ||
  652. +                 (buf[0]=='\n' && (key_sym & 0xff)=='\n'))
  653. +             {
  654. +                changing = FALSE;
  655. +                index = nameMarked;
  656. +             }
  657. +             else if (buf[0]=='\033' && (key_sym & 0xff)=='\033')
  658. +             {
  659. +                looping = FALSE;
  660. +                changing = FALSE;
  661. +                index = INVALID;
  662. +             }
  663. +             else if (buf[0] == '\b' || buf[0] == '\177')
  664. +             {
  665. +                if (name_index != 0)
  666. +                {
  667. +                   name[--name_index] = '\0';
  668. +                   strcpy (full_name, dir_name);
  669. +                   strcat (full_name, "/");
  670. +                   strcat (full_name, name);
  671. +                   for (i = 0; i < nameEntries; i++)
  672. +                      if (strncmp (nameDspPtr[i], name, name_index) == 0)
  673. +                         break;
  674. +                   if (i < nameEntries)
  675. +                   {
  676. +                      if (i < nameFirst)
  677. +                         nameFirst = i;
  678. +                      else if (i >= nameFirst+ITEM_DSPED)
  679. +                      {
  680. +                         if (i < nameEntries-ITEM_DSPED)
  681. +                            nameFirst = i;
  682. +                         else
  683. +                            nameFirst = nameEntries-ITEM_DSPED;
  684. +                      }
  685. +                      nameMarked = i;
  686. +                      RedrawNamePath (full_name, graph_start,
  687. +                            3*ROW_HEIGHT+defaultFontAsc+2);
  688. +                      RedrawNameScrollWin ();
  689. +                      RedrawDspWindow ();
  690. +                   }
  691. +                }
  692. +             }
  693. +             else if (key_sym>='\040' && key_sym<='\177')
  694. +             {
  695. +                if (buf[0] == '$')
  696. +                {
  697. +                   i = (nameEntries == 0) ? 0 : nameEntries-1;
  698. +                   strcpy (name, nameDspPtr[i]);
  699. +                }
  700. +                else
  701. +                {
  702. +                   name[name_index++] = buf[0];
  703. +                   name[name_index] = '\0';
  704. +                   for (i = 0; i < nameEntries; i++)
  705. +                      if (strncmp (nameDspPtr[i], name, name_index) == 0)
  706. +                         break;
  707. +                }
  708. +                if (i < nameEntries)
  709. +                {
  710. +                   if (i < nameFirst)
  711. +                      nameFirst = i;
  712. +                   else if (i >= nameFirst+ITEM_DSPED)
  713. +                   {
  714. +                      if (i < nameEntries-ITEM_DSPED)
  715. +                         nameFirst = i;
  716. +                      else
  717. +                         nameFirst = nameEntries-ITEM_DSPED;
  718. +                   }
  719. +                   nameMarked = i;
  720. +                   strcpy (full_name, dir_name);
  721. +                   strcat (full_name, "/");
  722. +                   strcat (full_name, name);
  723. +                   RedrawNamePath (full_name, graph_start,
  724. +                         3*ROW_HEIGHT+defaultFontAsc+2);
  725. +                   RedrawNameScrollWin ();
  726. +                   RedrawDspWindow ();
  727. +                }
  728. +                else
  729. +                   name[--name_index] = '\0';
  730. +             }
  731. +          }
  732. +          else if (input.type == ButtonPress)
  733. +          {
  734. +             button_ev = &(input.xbutton);
  735. +             if (button_ev->window == nameBaseWin)
  736. +             {
  737. +                if (PointInBBox (button_ev->x, button_ev->y, buttonBBox[0]))
  738. +                {
  739. +                   changing = FALSE;
  740. +                   index = nameMarked;
  741. +                }
  742. +                else if (PointInBBox (button_ev->x, button_ev->y, buttonBBox[1]))
  743. +                {
  744. +                   looping = FALSE;
  745. +                   changing = FALSE;
  746. +                   index = INVALID;
  747. +                }
  748. +             }
  749. +             else if (button_ev->window == nameScrollWin)
  750. +                NameScrollHandler (button_ev);
  751. +             else if (button_ev->window == nameDspWin)
  752. +             {
  753. +                if (NameDspHandler (button_ev) != INVALID)
  754. +                {
  755. +                   changing = FALSE;
  756. +                   index = nameMarked;
  757. +                }
  758. +                else if (nameMarked != INVALID)
  759. +                {
  760. +                   strcpy (name, nameDspPtr[nameMarked]);
  761. +                   strcpy (full_name, dir_name);
  762. +                   strcat (full_name, "/");
  763. +                   strcat (full_name, name);
  764. +                   RedrawNamePath (full_name, graph_start,
  765. +                         3*ROW_HEIGHT+defaultFontAsc+2);
  766. +                }
  767. +             }
  768. +          }
  769. +       }
  770. +       if (index != INVALID) strcpy (sel_str, nameDspPtr[index]);
  771. +       cfree (*nameDspPtr);
  772. +       cfree (nameDspPtr);
  773. +       if (index == INVALID) break;
  774. +       if (sel_str[strlen(sel_str)-1] == '/')
  775. +       {
  776. +          sel_str[strlen(sel_str)-1] = '\0';
  777. +          if (strcmp (sel_str, "..") == 0)
  778. +          {
  779. +             for (i = strlen(dir_name)-1; i>=0 && dir_name[i]!='/'; i--) ;
  780. +             if (i < 0)
  781. +                dir_name[0] = '\0';
  782. +             else
  783. +                dir_name[i] = '\0';
  784. +          }
  785. +          else
  786. +          {
  787. +             strcat (dir_name, "/");
  788. +             strcat (dir_name, sel_str);
  789. +          }
  790. +          dsp_ptr = topOfDirLinkList;
  791. +          for ( ; dsp_ptr != NULL; dsp_ptr = dsp_ptr->next) cfree (dsp_ptr);
  792. +          topOfDirLinkList = NULL;
  793. +          Msg ("Generating list of file names, please wait ...");
  794. +          if ((topOfDirLinkList = DirListing (dir_name)) == NULL)
  795. +          {
  796. +             *sel_str = '\0';
  797. +             break;
  798. +          }
  799. +          Msg ("");
  800. +       }
  801. +       else
  802. +          break;
  803. +    }
  804. +    if (grabbed) XUngrabKeyboard (mainDisplay, CurrentTime);
  805. +    strcpy (SelStr, dir_name);
  806. +    strcat (SelStr, "/");
  807. +    strcat (SelStr, sel_str);
  808. +    if (index == INVALID)
  809. +       DisplayButton (nameBaseWin, okCancelStr[1], 8, &buttonBBox[1],
  810. +             BUTTON_INVERT);
  811. +    else
  812. +       DisplayButton (nameBaseWin, okCancelStr[0], 8, &buttonBBox[0],
  813. +             BUTTON_INVERT);
  814. +    XDestroyWindow (mainDisplay, nameBaseWin);
  815. +    XSync (mainDisplay, FALSE);
  816. +    while (XCheckMaskEvent (mainDisplay, ExposureMask, &input)) ;
  817. +    return (index);
  818. + }
  819. + static
  820. + int ChooseAName (TopStr, SelStr)
  821. +    char    * TopStr, * SelStr;
  822. + {
  823. +    int            button_widths, str_width, graph_width;
  824. +    int            str_start, button_start, graph_start, index;
  825. +    int            dsp_w, dsp_h, x, y, w, h, i, len;
  826. +    XEvent        input, ev;
  827. +    int            changing = TRUE, grabbed = FALSE, name_index;
  828. +    char            buf[80], name[MAXPATHLENGTH];
  829. +    XKeyEvent        * key_ev;
  830. +    XButtonEvent        * button_ev;
  831. +    KeySym        key_sym;
  832. +    XComposeStatus    c_stat;
  833. +    XSetWindowAttributes    win_attrs;
  834. +    int            win_x, win_y, win_w, win_h, win_d, win_brdr_w;
  835. +    dsp_w = DisplayWidth (mainDisplay, mainScreen);
  836. +    dsp_h = DisplayHeight (mainDisplay, mainScreen);
  837. +    button_widths = ButtonWidth("OK", 8) + ButtonWidth("CANCEL", 8) +
  838. +          defaultFontWidth;
  839. +    str_width = defaultFontWidth * strlen (TopStr);
  840. +    graph_width = nameDspWinW + scrollBarW + 2 * brdrW;
  841. +    if (str_width > graph_width)
  842. +    {
  843. +       w = str_width + 4 * defaultFontWidth;
  844. +       str_start = 2 * defaultFontWidth;
  845. +       graph_start = (w - graph_width) / 2;
  846. +    }
  847. +    else
  848. +    {
  849. +       w = graph_width + 4 * defaultFontWidth;
  850. +       str_start = (w - str_width) / 2;
  851. +       graph_start = 2 * defaultFontWidth;
  852. +    }
  853. +    button_start = (w - button_widths) / 2;
  854. +    h = (8 + ITEM_DSPED) * ROW_HEIGHT;
  855. +    win_x = (w > dsp_w) ? 0 : (dsp_w - w)/2;
  856. +    win_y = (h > dsp_h) ? 0 : (dsp_h - h)/3;
  857. +    if ((nameBaseWin = XCreateSimpleWindow (mainDisplay, rootWindow,
  858. +          win_x, win_y, w, h, brdrW, myBorderPixel, myBgPixel)) == 0)
  859. +    { printf ("Could not create desired popup window!\n"); exit (-1); }
  860. +    XDefineCursor (mainDisplay, nameBaseWin, defaultCursor);
  861. +    if ((nameDspWin = XCreateSimpleWindow (mainDisplay, nameBaseWin, graph_start,
  862. +          5*ROW_HEIGHT, nameDspW, nameDspH, brdrW, myBorderPixel,
  863. +          myBgPixel)) == 0)
  864. +    { printf ("Could not create desired popup window!\n"); exit (-1); }
  865. +    if ((nameScrollWin = XCreateSimpleWindow (mainDisplay, nameBaseWin,
  866. +          graph_start+nameDspWinW, 5*ROW_HEIGHT, scrollBarW, nameDspH,
  867. +          brdrW, myBorderPixel, myBgPixel)) == 0)
  868. +    { printf ("Could not create desired popup scroll window!\n"); exit (-1); }
  869. +    win_attrs.save_under = True;
  870. +    XChangeWindowAttributes (mainDisplay, nameBaseWin, CWSaveUnder, &win_attrs);
  871. +    XSetTransientForHint (mainDisplay, nameBaseWin, mainWindow);
  872. +    XMapWindow (mainDisplay, nameBaseWin);
  873. +    XSelectInput (mainDisplay, nameBaseWin,
  874. +          KeyPressMask | ButtonPressMask | ExposureMask);
  875. +    XMapWindow (mainDisplay, nameDspWin);
  876. +    XSelectInput (mainDisplay, nameDspWin,
  877. +          KeyPressMask | ButtonPressMask | ExposureMask);
  878. +    XMapWindow (mainDisplay, nameScrollWin);
  879. +    XSelectInput (mainDisplay, nameScrollWin,
  880. +          KeyPressMask | ButtonPressMask | ExposureMask);
  881. +    justClicked = FALSE;
  882. +    Msg ("");
  883. +    name[0] = '\0';
  884. +    name_index = 0;
  885. +    nameMarked = INVALID;
  886. +    while (changing)
  887. +    {
  888.         XNextEvent (mainDisplay, &input);
  889.         if (input.type == Expose)
  890. ***************
  891. *** 426,430 ****
  892.         {
  893.            if (input.xany.window == nameBaseWin)
  894. !             RedrawNameBaseWindow (Str, str_start, button_start, w, h);
  895.            else if (input.xany.window == nameScrollWin)
  896.               RedrawNameScrollWin ();
  897. --- 1123,1128 ----
  898.         {
  899.            if (input.xany.window == nameBaseWin)
  900. !             RedrawNameBaseWindow (TopStr, name, str_start, graph_start,
  901. !                   button_start, w, h);
  902.            else if (input.xany.window == nameScrollWin)
  903.               RedrawNameScrollWin ();
  904. ***************
  905. *** 432,436 ****
  906.               RedrawDspWindow ();
  907.   
  908. !          if (!grabbed)
  909.            {
  910.               XGrabKeyboard (mainDisplay, nameBaseWin, False,
  911. --- 1130,1134 ----
  912.               RedrawDspWindow ();
  913.   
  914. ! /*       if (!grabbed)
  915.            {
  916.               XGrabKeyboard (mainDisplay, nameBaseWin, False,
  917. ***************
  918. *** 437,441 ****
  919.                     GrabModeAsync, GrabModeAsync, CurrentTime);
  920.               grabbed = TRUE;
  921. !          }
  922.   
  923.            continue;
  924. --- 1135,1139 ----
  925.                     GrabModeAsync, GrabModeAsync, CurrentTime);
  926.               grabbed = TRUE;
  927. !          } */
  928.   
  929.            continue;
  930. ***************
  931. *** 446,466 ****
  932.            XLookupString (key_ev, buf, 80, &key_sym, &c_stat);
  933.   
  934. !          if (buf[0] == '\r' || buf[0] == '\n')
  935.            {
  936. !             looping = FALSE;
  937.               index = nameMarked;
  938.            }
  939. !          else if (buf[0] == '\033')
  940.            {
  941. !             looping = FALSE;
  942.               index = INVALID;
  943.            }
  944.            else if (key_sym>='\040' && key_sym<='\177')
  945.            {
  946.               if (buf[0] == '$')
  947.                  i = (nameEntries == 0) ? 0 : nameEntries-1;
  948.               else
  949.                  for (i = 0; i < nameEntries; i++)
  950. !                   if (*nameDspPtr[i] == buf[0]) break;
  951.               if (i < nameEntries)
  952.               {
  953. --- 1144,1202 ----
  954.            XLookupString (key_ev, buf, 80, &key_sym, &c_stat);
  955.   
  956. !          if ((buf[0]=='\r' && (key_sym & 0xff)=='\r') ||
  957. !              (buf[0]=='\n' && (key_sym & 0xff)=='\n'))
  958.            {
  959. !             changing = FALSE;
  960.               index = nameMarked;
  961.            }
  962. !          else if (buf[0]=='\033' && (key_sym & 0xff)=='\033')
  963.            {
  964. !             changing = FALSE;
  965.               index = INVALID;
  966.            }
  967. +          else if (buf[0] == '\b' || buf[0] == '\177')
  968. +          {
  969. +             if (name_index != 0)
  970. +             {
  971. +                name[--name_index] = '\0';
  972. +                for (i = 0; i < nameEntries; i++)
  973. +                   if (strncmp (nameDspPtr[i], name, name_index) == 0)
  974. +                      break;
  975. +                if (i < nameEntries)
  976. +                {
  977. +                   if (i < nameFirst)
  978. +                      nameFirst = i;
  979. +                   else if (i >= nameFirst+ITEM_DSPED)
  980. +                   {
  981. +                      if (i < nameEntries-ITEM_DSPED)
  982. +                         nameFirst = i;
  983. +                      else
  984. +                         nameFirst = nameEntries-ITEM_DSPED;
  985. +                   }
  986. +                   nameMarked = i;
  987. +                   RedrawNamePath (name, graph_start,
  988. +                         3*ROW_HEIGHT+defaultFontAsc+2);
  989. +                   RedrawNameScrollWin ();
  990. +                   RedrawDspWindow ();
  991. +                }
  992. +             }
  993. +          }
  994.            else if (key_sym>='\040' && key_sym<='\177')
  995.            {
  996.               if (buf[0] == '$')
  997. +             {
  998.                  i = (nameEntries == 0) ? 0 : nameEntries-1;
  999. +                strcpy (name, nameDspPtr[i]);
  1000. +             }
  1001.               else
  1002. +             {
  1003. +                name[name_index++] = buf[0];
  1004. +                name[name_index] = '\0';
  1005.                  for (i = 0; i < nameEntries; i++)
  1006. !                   if (strncmp (nameDspPtr[i], name, name_index) == 0)
  1007. !                      break;
  1008. !             }
  1009.               if (i < nameEntries)
  1010.               {
  1011. ***************
  1012. *** 475,481 ****
  1013. --- 1211,1222 ----
  1014.                  }
  1015.                  nameMarked = i;
  1016. +                RedrawNamePath (name, graph_start,
  1017. +                      3*ROW_HEIGHT+defaultFontAsc+2);
  1018.                  RedrawNameScrollWin ();
  1019.                  RedrawDspWindow ();
  1020.               }
  1021. +             else
  1022. +                name[--name_index] = '\0';
  1023.            }
  1024.         }
  1025. ***************
  1026. *** 487,491 ****
  1027.               if (PointInBBox (button_ev->x, button_ev->y, buttonBBox[0]))
  1028.               {
  1029. !                looping = FALSE;
  1030.                  index = nameMarked;
  1031.               }
  1032. --- 1228,1232 ----
  1033.               if (PointInBBox (button_ev->x, button_ev->y, buttonBBox[0]))
  1034.               {
  1035. !                changing = FALSE;
  1036.                  index = nameMarked;
  1037.               }
  1038. ***************
  1039. *** 492,496 ****
  1040.               else if (PointInBBox (button_ev->x, button_ev->y, buttonBBox[1]))
  1041.               {
  1042. !                looping = FALSE;
  1043.                  index = INVALID;
  1044.               }
  1045. --- 1233,1237 ----
  1046.               else if (PointInBBox (button_ev->x, button_ev->y, buttonBBox[1]))
  1047.               {
  1048. !                changing = FALSE;
  1049.                  index = INVALID;
  1050.               }
  1051. ***************
  1052. *** 502,508 ****
  1053.               if (NameDspHandler (button_ev) != INVALID)
  1054.               {
  1055. !                looping = FALSE;
  1056.                  index = nameMarked;
  1057.               }
  1058.            }
  1059.         }
  1060. --- 1243,1256 ----
  1061.               if (NameDspHandler (button_ev) != INVALID)
  1062.               {
  1063. !                changing = FALSE;
  1064.                  index = nameMarked;
  1065.               }
  1066. +             else if (nameMarked != INVALID)
  1067. +             {
  1068. +                strcpy (name, nameDspPtr[nameMarked]);
  1069. +                name_index = strlen (name);
  1070. +                RedrawNamePath (name, graph_start,
  1071. +                      3*ROW_HEIGHT+defaultFontAsc+2);
  1072. +             }
  1073.            }
  1074.         }
  1075. ***************
  1076. *** 514,519 ****
  1077. --- 1262,1270 ----
  1078.               BUTTON_INVERT);
  1079.      else
  1080. +    {
  1081. +       strcpy (SelStr, nameDspPtr[index]);
  1082.         DisplayButton (nameBaseWin, okCancelStr[0], 8, &buttonBBox[0],
  1083.               BUTTON_INVERT);
  1084. +    }
  1085.   
  1086.      XDestroyWindow (mainDisplay, nameBaseWin);
  1087. ***************
  1088. *** 523,698 ****
  1089.   }
  1090.   
  1091. ! static
  1092. ! int    LargerStr (S1, S2)
  1093. !    register char    * S1, * S2;
  1094. !    /* returns TRUE if S1 > S2 */
  1095.   {
  1096. !    while (*S1 == *S2 && *S1 != '\0' && *S2 != '\0') { S1++; S2++; }
  1097.   
  1098. !    return (*S1 > *S2);
  1099. ! }
  1100. ! static
  1101. ! DspList * DirListing (Path, Extension, Entries)
  1102. !    char    * Path, * Extension;
  1103. !    int    * Entries;
  1104. ! {
  1105. !    DspList        * dsp_ptr = NULL, * head_ptr, * tail_ptr, * p, * p1;
  1106. !    DIR            * dirp;
  1107. !    struct direct    * d;
  1108. !    int            len, ext_len, count = 0;
  1109. !    char            ext[MAXPATHLENGTH];
  1110. !    if (*Path == '\0')
  1111.      {
  1112. !       if ((dirp = opendir (".")) == NULL) return (NULL);
  1113. !    }
  1114. !    else
  1115. !    {
  1116. !       if ((dirp = opendir (Path)) == NULL) return (NULL);
  1117. !    }
  1118.   
  1119. !    strcpy (ext, ".");
  1120. !    strcat (ext, Extension);
  1121. !    ext_len = strlen (ext);
  1122. !    head_ptr = tail_ptr = NULL;
  1123. !    while ((d = readdir (dirp)) != NULL)
  1124. !    {
  1125. !       len = strlen (d->d_name);
  1126. !       if (len > ext_len && (strcmp (ext, &d->d_name[len-ext_len]) == 0))
  1127. !       {
  1128. !          d->d_name[len-ext_len] = '\0';
  1129. !          dsp_ptr = (DspList *) calloc (1, sizeof(DspList));
  1130. !          strcpy (dsp_ptr->itemstr, d->d_name);
  1131. !          if (head_ptr == NULL)
  1132. !             head_ptr = tail_ptr = dsp_ptr;
  1133. !          else
  1134. !          {
  1135. !             p1 = NULL;
  1136. !             for (p = head_ptr; p != NULL; p = p->next)
  1137. !                if (LargerStr (d->d_name, p->itemstr))
  1138. !                   p1 = p;
  1139. !                else
  1140. !                   break;
  1141. !             dsp_ptr->next = p;
  1142. !             if (p == NULL)
  1143. !             {  /* dsp_ptr has the largest element */
  1144. !                tail_ptr->next = dsp_ptr;
  1145. !                tail_ptr = dsp_ptr;
  1146. !             }
  1147. !             else if (p1 == NULL)
  1148. !                head_ptr = dsp_ptr;
  1149. !             else
  1150. !                p1->next = dsp_ptr;
  1151. !          }
  1152. !          count++;
  1153. !       }
  1154.      }
  1155. !    closedir (dirp);
  1156. !    *Entries = count;
  1157. !    return (head_ptr);
  1158.   }
  1159.   
  1160. ! int SelectFileName (Extension, Str, SelStr)
  1161. !    char    * Extension, * Str, * SelStr;
  1162.   {
  1163. !    register int    i, index;
  1164. !    char        s[MAXPATHLENGTH], full_name[MAXPATHLENGTH];
  1165.      DspList    * dsp_ptr;
  1166.   
  1167. !    sprintf (s, "Generating list of file names, please wait ...");
  1168.      Msg (s);
  1169. -    strcpy (full_name, curDomainName);
  1170.   
  1171. !    if ((dsp_ptr = DirListing (curDomainName, Extension, &nameEntries)) == NULL)
  1172. !    {
  1173. !       strcpy (s, "No appropriate files to select from.");
  1174. !       Msg (s);
  1175. !       *SelStr = '\0';
  1176. !       return (INVALID);
  1177. !    }
  1178.   
  1179. !    nameDspPtr = MakeNameDspItemArray (nameEntries, dsp_ptr);
  1180.      nameFirst = 0;
  1181.      nameMarked = 0;
  1182.   
  1183. !    if ((index = Names (Str)) == INVALID)
  1184. !       *SelStr = '\0';
  1185.      else
  1186. !       strcpy (SelStr, nameDspPtr[index]);
  1187. !    for ( ; dsp_ptr != NULL; dsp_ptr = dsp_ptr->next) cfree (dsp_ptr);
  1188. !    cfree (nameDspPtr[0]);
  1189.      cfree (nameDspPtr);
  1190.   
  1191. !    s[0] = '\0';
  1192. !    Msg (s);
  1193.      return (index);
  1194.   }
  1195.   
  1196.   static
  1197. ! DspList * DomainListing (Path, Entries)
  1198. !    char    * Path;
  1199.      int    * Entries;
  1200.   {
  1201. !    DspList        * dsp_ptr = NULL, * head_ptr, * tail_ptr, * p, * p1;
  1202. !    DIR            * dirp, * dp;
  1203. !    struct direct    * d;
  1204. !    struct stat        stat_buf;
  1205. !    int            count = 0;
  1206. !    char            path[255], s[255];
  1207.   
  1208. !    if (*Path == '\0')
  1209. !       strcpy (path, ".");
  1210. !    else
  1211. !       strcpy (path, Path);
  1212.   
  1213. !    if ((dirp = opendir (path)) == NULL) return (NULL);
  1214.   
  1215. -    strcat (path, "/");
  1216.      head_ptr = tail_ptr = NULL;
  1217. !    while ((d = readdir (dirp)) != NULL)
  1218.      {
  1219. !       strcpy (s, path);
  1220. !       strcat (s, d->d_name);
  1221. !       stat (s, &stat_buf);
  1222. !       if (stat_buf.st_mode & S_IFDIR)
  1223.         {
  1224. !          dsp_ptr = (DspList *) calloc (1, sizeof(DspList));
  1225. !          strcpy (dsp_ptr->itemstr, d->d_name);
  1226. !          if (head_ptr == NULL)
  1227. !             head_ptr = tail_ptr = dsp_ptr;
  1228. !          else
  1229. !          {
  1230. !             p1 = NULL;
  1231. !             for (p = head_ptr; p != NULL; p = p->next)
  1232. !                if (LargerStr (d->d_name, p->itemstr))
  1233. !                   p1 = p;
  1234. !                else
  1235. !                   break;
  1236.   
  1237. !             dsp_ptr->next = p;
  1238. !             if (p == NULL)
  1239. !             {  /* dsp_ptr has the largest element */
  1240. !                tail_ptr->next = dsp_ptr;
  1241. !                tail_ptr = dsp_ptr;
  1242. !             }
  1243. !             else if (p1 == NULL)
  1244. !                head_ptr = dsp_ptr;
  1245.               else
  1246. !                p1->next = dsp_ptr;
  1247.            }
  1248. !          count++;
  1249.         }
  1250.      }
  1251. -    closedir (dirp);
  1252. -    *Entries = count;
  1253.      return (head_ptr);
  1254.   }
  1255. --- 1274,1406 ----
  1256.   }
  1257.   
  1258. ! int SelectFileName (MsgStr, SelStr)
  1259. !    char    * MsgStr, * SelStr;
  1260.   {
  1261. !    int        index = INVALID, saved_num_dir_entries;
  1262. !    DspList    * dsp_ptr;
  1263.   
  1264. !    saved_num_dir_entries = numDirEntries;
  1265. !    if ((index = DirNames (MsgStr, SelStr)) == INVALID)
  1266.      {
  1267. !       numDirEntries = saved_num_dir_entries;
  1268. !       dsp_ptr = topOfDirLinkList;
  1269. !       for ( ; dsp_ptr != NULL; dsp_ptr = dsp_ptr->next) cfree (dsp_ptr);
  1270. !       topOfDirLinkList = NULL;
  1271.   
  1272. !       *SelStr = '\0';
  1273. !       return (INVALID);
  1274.      }
  1275. !    BuildDirList ();
  1276. !    Msg ("");
  1277. !    return (index);
  1278.   }
  1279.   
  1280. ! int SelectSymbolName (SelSymName, PathName)
  1281. !    char    * SelSymName, * PathName;
  1282.   {
  1283. !    register int    i, index = INVALID;
  1284. !    char        s[MAXPATHLENGTH], msg[MAXSTRING];
  1285.      DspList    * dsp_ptr;
  1286.   
  1287. !    sprintf (s,
  1288. !          "Generating a list of symbol names in '%s' domain, please wait ...",
  1289. !          curDomainName);
  1290.      Msg (s);
  1291.   
  1292. ! /* if ((topOfSymLinkList = SymbolListing ()) == NULL) */
  1293. ! /* { */
  1294. ! /*    Msg ("No symbol found!"); */
  1295. ! /*    SelSymName[0] = '\0'; */
  1296. ! /*    PathName[0] = '\0'; */
  1297. ! /*    return (INVALID); */
  1298. ! /* } */
  1299. ! /* BuildSymbolList (); */
  1300.   
  1301. !    nameEntries = numSymbols;
  1302. !    nameDspPtr = MakeNameDspItemArray (nameEntries, symbolList);
  1303.      nameFirst = 0;
  1304.      nameMarked = 0;
  1305.   
  1306. !    sprintf (msg, "Please select a symbol to INSTANTIATE in the '%s' domain ...",
  1307. !          curDomainName);
  1308. !    if ((index = ChooseAName (msg, SelSymName)) == INVALID)
  1309. !    {
  1310. !       *SelSymName = '\0';
  1311. !       *PathName = '\0';
  1312. !    }
  1313.      else
  1314. !    {
  1315. !       strcpy (SelSymName, nameDspPtr[index]);
  1316. !       strcpy (PathName, symbolList[index].pathstr);
  1317. !    }
  1318. !    cfree (*nameDspPtr);
  1319.      cfree (nameDspPtr);
  1320.   
  1321. !    Msg ("");
  1322.      return (index);
  1323.   }
  1324.   
  1325. + int GetSymbolPath (SymName, PathName)
  1326. +    char    * SymName, * PathName;
  1327. + {
  1328. +    register int    i;
  1329. +    for (i = 0; i < numSymbols; i++)
  1330. +       if (strcmp (SymName, symbolList[i].itemstr) == 0)
  1331. +       {
  1332. +          strcpy (PathName, symbolList[i].pathstr);
  1333. +          return (TRUE);
  1334. +       }
  1335. +    return (FALSE);
  1336. + }
  1337.   static
  1338. ! DspList * DomainListing (Entries)
  1339.      int    * Entries;
  1340.   {
  1341. !    register int    i, default_index = 0;
  1342. !    char        s[MAXSTRING], * c_ptr;
  1343. !    DspList    * dsp_ptr = NULL, * head_ptr, * tail_ptr, * p, * p1;
  1344.   
  1345. !    if ((c_ptr = XGetDefault (mainDisplay, TOOL_NAME, "MaxDomains")) == NULL)
  1346. !       return (NULL);
  1347.   
  1348. !    *Entries = atoi (c_ptr);
  1349.   
  1350.      head_ptr = tail_ptr = NULL;
  1351. !    for (i = 0; i < *Entries; i++)
  1352.      {
  1353. !       sprintf (s, "Domain%1d", i);
  1354. !       if ((c_ptr = XGetDefault (mainDisplay, TOOL_NAME, s)) == NULL)
  1355.         {
  1356. !          for ( ; head_ptr != NULL; head_ptr = head_ptr->next) cfree (head_ptr);
  1357. !          return (NULL);
  1358. !       }
  1359.   
  1360. !       dsp_ptr = (DspList *) calloc (1, sizeof(DspList));
  1361. !       strcpy (dsp_ptr->itemstr, c_ptr);
  1362. !       if (head_ptr == NULL)
  1363. !          head_ptr = tail_ptr = dsp_ptr;
  1364. !       else
  1365. !       {
  1366. !          p1 = NULL;
  1367. !          for (p = head_ptr; p != NULL; p = p->next)
  1368. !             if (LargerStr (dsp_ptr->itemstr, p->itemstr))
  1369. !                p1 = p;
  1370.               else
  1371. !                break;
  1372. !          dsp_ptr->next = p;
  1373. !          if (p == NULL)
  1374. !          {  /* dsp_ptr has the largest element */
  1375. !             tail_ptr->next = dsp_ptr;
  1376. !             tail_ptr = dsp_ptr;
  1377.            }
  1378. !          else if (p1 == NULL)
  1379. !             head_ptr = dsp_ptr;
  1380. !          else
  1381. !             p1->next = dsp_ptr;
  1382.         }
  1383.      }
  1384.      return (head_ptr);
  1385.   }
  1386. ***************
  1387. *** 701,712 ****
  1388.      char    * SelStr;
  1389.   {
  1390. !    register int        i, index;
  1391. !    char            s[MAXPATHLENGTH];
  1392. !    DspList        * dsp_ptr;
  1393.   
  1394.      Msg ("Generating list of domain names, please wait ...");
  1395.   
  1396. !    if ((dsp_ptr = DomainListing (curDomainName, &nameEntries)) == NULL)
  1397.      {
  1398.         *SelStr = '\0';
  1399.         return (INVALID);
  1400. --- 1409,1421 ----
  1401.      char    * SelStr;
  1402.   {
  1403. !    int        index;
  1404. !    char        s[MAXPATHLENGTH];
  1405. !    DspList    * dsp_ptr;
  1406.   
  1407.      Msg ("Generating list of domain names, please wait ...");
  1408.   
  1409. !    if ((dsp_ptr = DomainListing (&nameEntries)) == NULL)
  1410.      {
  1411. +       Msg ("No domain names found.");
  1412.         *SelStr = '\0';
  1413.         return (INVALID);
  1414. ***************
  1415. *** 717,721 ****
  1416.      nameMarked = 0;
  1417.   
  1418. !    if ((index = Names ("PLEASE SELECT NEW DOMAIN ...")) == INVALID)
  1419.         *SelStr = '\0';
  1420.      else
  1421. --- 1426,1430 ----
  1422.      nameMarked = 0;
  1423.   
  1424. !    if ((index = ChooseAName ("Please select a new DOMAIN ...", "")) == INVALID)
  1425.         *SelStr = '\0';
  1426.      else
  1427. ***************
  1428. *** 730,732 ****
  1429. --- 1439,1465 ----
  1430.   
  1431.      return (index);
  1432. + }
  1433. + void SetCurDir (FileName)
  1434. +    char    * FileName;
  1435. + {
  1436. +    register int    i;
  1437. +    char        file_name[MAXPATHLENGTH];
  1438. +    if (*FileName != '/')
  1439. +       strcpy (file_name, bootDir);
  1440. +    else
  1441. +       strcpy (file_name, FileName);
  1442. +    for (i = strlen(file_name)-1; i>=0 && file_name[i]!='/'; i--) ;
  1443. +    if (i < 0)
  1444. +       TwoLineMsg ("Error:  No '/' found in SetCurDir ().",
  1445. +                   "        curDir and curFileName not set.");
  1446. +    else
  1447. +    {
  1448. +       strcpy (curFileName, &file_name[i+1]);
  1449. +       file_name[i] = '\0';
  1450. +       strcpy (curDir, file_name);
  1451. +    }
  1452.   }
  1453. ---------------------------------> cut here <---------------------------------
  1454. -- 
  1455. Bill Cheng // UCLA Computer Science Department // (213) 206-7135
  1456. 3277 Boelter Hall // Los Angeles, California 90024 // USA
  1457. william@CS.UCLA.EDU      ...!{uunet|ucbvax}!cs.ucla.edu!william
  1458.  
  1459. dan
  1460. ----------------------------------------------------
  1461. O'Reilly && Associates   argv@sun.com / argv@ora.com
  1462. Opinions expressed reflect those of the author only.
  1463. --
  1464. dan
  1465. ----------------------------------------------------
  1466. O'Reilly && Associates   argv@sun.com / argv@ora.com
  1467. Opinions expressed reflect those of the author only.
  1468.